#include<bits/stdc++.h>
#define ll long long
#define uint unsigned long long
using namespace std;

const int N = 3e6 + 10,M = 6e6 + 10;

int L, C, P;
int tr[N][26], fail[N], seg[N], idx;
int pre[N], ans[N];

struct edge1
{
    int h[N], id[M], c[M], ne[M], idx = 0;
    void init() { memset(h, -1, sizeof h); idx = 0; }
    void add(int x, int y, int w) { id[idx] = y;c[idx] = w; ne[idx] = h[x];h[x] = idx++; }
}g;

struct edge2
{
    int h[N], e[N], ne[N], idx = 0;
    void init() { memset(h, -1, sizeof h); idx = 0; }
    void add(int x, int y) { e[idx] = y; ne[idx] = h[x];h[x] = idx++; }
}adj;

void insert(const string& s, int id)
{
    int p = 0;
    ll c = 1;
    for (char it : s) {
        int ch = it - 'a';
        if (tr[p][ch] == 0) tr[p][ch] = ++idx;
        p = tr[p][ch];
        c = (c * C) % P;
        g.add(p, id, c);
    }
    seg[id] = p;
}

void setfail()
{
    queue<int> q;
    for (int i = 0;i < 26;i++) if (tr[0][i]) { q.push(tr[0][i]); }
    while (!q.empty()) {
        int now = q.front();q.pop();
        for (int i = 0;i < 26;i++)
            if (tr[now][i]) {
                fail[tr[now][i]] = tr[fail[now]][i];
                q.push(tr[now][i]);
            } else tr[now][i] = tr[fail[now]][i];
    }
}

int res = 0;
void dfs(int x)
{
    vector<pair<int, int>> tmp;
    for (int i = g.h[x];i != -1;i = g.ne[i]) {
        int id = g.id[i], c = g.c[i];
        res = (res + c - pre[id] + P) % P;
        tmp.push_back({ id, pre[id] });
        pre[id] = c;
    }

    ans[x] = res;
    for (int i = adj.h[x];i != -1;i = adj.ne[i]) dfs(adj.e[i]);

    for (auto& [id, c] : tmp) {
        res = (res - pre[id] + c + P) % P;
        pre[id] = c;
    }
}

void solve()
{
    g.init();adj.init();
    cin >> L >> C >> P;
    for (int i = 1;i <= L;i++) {
        string s;cin >> s;
        g.add(0, i, 1);
        insert(s, i);
    }
    setfail();
    for (int i = 1;i <= idx;i++) adj.add(fail[i], i);
    dfs(0);

    int res = 0;
    for (int i = 1;i <= L;i++) (res += ans[seg[i]]) %= P;
    cout << res << '\n';
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}